#include "Button.h"

Button::Button(IDirect3DTexture9* highTex, IDirect3DTexture9* backTex, bool isSelected){
	mHighTex	= highTex;
	mBackTex	= backTex;
	mSelected	= isSelected;
	mWidth  =132.0f;
	mHeight = 32.0f;
	mCenter = D3DXVECTOR3(mWidth/2, mHeight/2, 0.0f);
	mSpritePos.x = mCenter.x;
	mSpritePos.y = mCenter.y;
}

Button::~Button(){
	mHighTex = NULL;
	mBackTex = NULL;
}

void Button::update(float dt){
	
}

void Button::render(ID3DXSprite* mSprite){
	if(mHighTex == 0 || mBackTex == 0) return;

	//HR(gDevice->SetRenderState(D3DRS_ALPHATESTENABLE,true));
	D3DXMATRIX S;
	D3DXMatrixScaling(&S,0.52f,-0.52f,1.0f);
	D3DXMATRIX T;
	D3DXMatrixTranslation(&T,mPos.x, mPos.y, 0);
	mSprite->SetTransform(&(S*T));
	RECT rect = calRenderRECT(mSpritePos,mWidth,mHeight);
	
	if(mSelected){
		mSprite->Draw(mHighTex,&rect,&mCenter,0,D3DCOLOR_XRGB(255, 255, 255));
	}else{
		mSprite->Draw(mBackTex,&rect,&mCenter,0,D3DCOLOR_XRGB(255, 255, 255));
	}
	mSprite->Flush();
	//gDevice->SetRenderState(D3DRS_ALPHATESTENABLE,false);
}

void Button::setSelected(bool selected){
	mSelected = selected;
}

bool Button::getSelected(){
	return mSelected;
}